package com.hmall.api.item.fallbackfactory;

import com.hmall.api.item.ItemClient;
import com.hmall.api.item.dto.ItemDTO;
import com.hmall.api.trade.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 远程调用商品服务接口的直接降级处理工厂
 *
 * @Author haoye
 * @Date 2025/11/10 9:55
 */
@Slf4j
@Component
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {

    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {

                log.error("[Feign接口-查询商品数据失败], ids：{}, 错误原因：", ids, cause);
                return Collections.emptyList();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {

                log.error("[Feign接口-扣减库存失败], items：{}, 错误原因：", items, cause);
            }
        };
    }
}
